package com.example.teesystem.entityDto;

import com.example.teesystem.common.cache.KnowledgeCache;
import com.example.teesystem.entity.Issue;
import com.example.teesystem.entity.Knowledge;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : NieYaShi
 * @version : v1.0
 * @createTime : 2022/4/28 18:52
 */
@Data
public class AnswerMessage {
    private String answer;
    private String analysis;
    private boolean result;
    private List<Knowledge> knowledgeList = new ArrayList<>();

    public AnswerMessage(Issue issue, boolean result){
        BeanUtils.copyProperties(issue, this);
        this.result = result;
        if (issue.getKnowledgeList() != null && !issue.getKnowledgeList().equals("")) {
            String[] knowledgeIds = issue.getKnowledgeList().split("\\$");
            Knowledge def = new Knowledge();
            def.setMessage("");
            for (String knowledgeId : knowledgeIds) {
                Knowledge knowledge = KnowledgeCache.knowledgeMap.getOrDefault(Integer.parseInt(knowledgeId), def);
                knowledgeList.add(knowledge);
            }
        }
    }
}
